﻿# ====================================================================================
# Description:	Installation script for Office Web Apps 2013
# FileName:		SPOWAInstallerMain.ps1
# Author:		Jean-Cyril DROUHIN
# Date:			January 30, 2014
# Version:		1.0
# URL:			http://spowainstaller.codeplex.com
# Licence:		MS-PL
# ====================================================================================

param 
(
    [string]$inputFile = $(throw '- Need parameter input file')
)
# Get the content of the SPOWAInstallerInput.xml file
[xml]$xmlinput = (Get-Content $inputFile)

#Region Setup Paths & Environment
cls
$Host.UI.RawUI.WindowTitle = " -- SPOWAInstaller script -- $env:COMPUTERNAME --"
$0 = $myInvocation.MyCommand.Definition
$env:dp0 = [System.IO.Path]::GetDirectoryName($0)
$bits = Get-Item $env:dp0 | Split-Path -Parent

# Logging PowerShell script in rtf file 
$logfolder = Split-Path -parent $MyInvocation.MyCommand.Definition
$logTime = Get-Date -Format yyyy-MM-dd_h-mm
$logFile = "$logfolder\SPOWAInstaller_script_$logTime.rtf"
Start-Transcript -Path $logFile -Append -Force

$DateStarted = Get-date
Write-Host -ForegroundColor Green "-----------------------------------"
Write-Host -ForegroundColor Green "| Automated Script - SPOWAInstaller |"
Write-Host -ForegroundColor Green "| Started on: $DateStarted |"
Write-Host -ForegroundColor Green "-----------------------------------"

# Check if Office Web Apps binaries are in the \OWA\OfficeWebApps\ subfolder
If (Test-Path -Path "$bits\OWA\OfficeWebApps\setup.exe")
{
	$env:SPbits = $bits+"\OWA\OfficeWebApps"
	Write-Host -ForegroundColor White " - Office Web Apps binaries found in $env:SPbits"
}
Else
{
	Throw " - Cannot locate Office Web Apps binaries; please check that the files are in the \OfficeWebApps subfolder."
}

Write-Host -ForegroundColor White " - Setting power management plan to `"High Performance`"..."
Start-Process -FilePath "$env:SystemRoot\system32\powercfg.exe" -ArgumentList "/s 8c5e7fda-e8bf-4a96-9a85-a6e23a8c635c" -NoNewWindow
#EndRegion

#Region External Functions
. "$env:dp0\SPOWAInstallerFunctions.ps1"
#EndRegion

#Region Install Office Web Apps binaries
#$spInstalled = (Get-OWAInstall)

DisableIEEnhancedSecurity $xmlinput
DisableLoopbackCheck $xmlinput
DisableCRLCheck $xmlinput

#InstallPrerequisites
ProvisionIISServerRole
ConfigureIISLogging $xmlinput
#InstallOfficeWebApps $xmlinput
#InstallLanguagePacks $xmlinput
#ConfigureOfficeWebApps $xmlinput

#EndRegion

$DateEnded = Get-date
Write-Host -ForegroundColor Green "-----------------------------------"
Write-Host -ForegroundColor Green "| Automated Script - WarmUp Urls |"
Write-Host -ForegroundColor Green "| Started on: $DateStarted |"
Write-Host -ForegroundColor Green "| Completed on: $DateEnded |"
Write-Host -ForegroundColor Green "-----------------------------------"

Stop-Transcript
#Exit